//
//  RTNetWroking.h
//  RtMart
//
//  Created by 福利购Mac on 16/12/2.
//  Copyright © 2016年 JASON. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, NetWorkingCacheType){
    RTCacheTypeReturnCacheDataThenLoad = 0,///< 有缓存就先返回缓存，同步请求数据
    RTCacheTypeReloadIgnoringLocalCacheData, ///< 忽略缓存，重新请求
    RTCacheTypeReturnCacheDataElseLoad,///< 有缓存就用缓存，没有缓存就重新请求(用于数据不变时)
    RTCacheTypeReturnCacheDataDontLoad,///< 有缓存就用缓存，没有缓存就不发请求，当做请求出错处理（用于离线模式）
    RTCacheTypeReturnCacheDataExpireThenLoad///< 有缓存就用缓存，如果过期了就重新请求 没过期就不请求
};

@interface RTCache : NSObject

@property (nonatomic, copy) NSString *fileName;//缓存文件名
@property (nonatomic, assign) BOOL result;//是否需要重新请求数据



@end

@interface RTNetWroking : NSObject
/**网络请求单例*/
+ (instancetype)shareNetWorking;

/**普通get请求,没有缓存*/
- (void)getRequestWithURL:(NSString *)url parameters:(NSDictionary *)dict successBlock:(void(^)(id  responseObject))success faildBlock:(void(^)(NSError *error))faild;

/**get请求,可以设置缓存. 特别注意,返回的最外层必须是字典的,才可以用.否则不允许使用.请用普通的post请求  */
- (void)getRequestWithURL:(NSString *)url params:(NSDictionary *)params cacheType:(NetWorkingCacheType)cacheType success:(void (^)(id responseObject))success failure:(void (^)(NSError * error))failure;

/**普通的post请求*/
- (void)postRequestWithURL:(NSString *)url parameters:(NSDictionary *)params successBlock:(void(^)(id  responseObject))success faildBlock:(void(^)(NSError *error))faild;

//Json post请求
- (void)jsonPost:(NSString *)url params:(NSDictionary *)params cacheType:(NetWorkingCacheType)cacheType success:(void(^)(id  responseObject))success failure:(void (^)(NSError *))failure;

/**post请求,可以设置缓存 特别注意,返回的最外层必须是字典的,才可以用.否则不允许使用.请用普通的post请求*/
- (void)postRequestWithURL:(NSString *)url params:(NSDictionary *)params cacheType:(NetWorkingCacheType)cacheType success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure;

/**上传单张图片*/
-(void)upLoadFileWithURL:(NSString *)url parameters:(NSDictionary *)dict image:(UIImage *)image successBlock:(void(^)(id responseObject))sucess imageUrl:(void(^)(NSString *url))urlBlock faildBlock:(void(^)(NSError *error))faild;

/**上传多张图片*/
-(void)upLoadMultiFileWithURL:(NSString *)url parameters:(NSDictionary *)dict imageArray:(NSArray<UIImage *> *)imageArr successBlock:(void(^)(id responseObject))sucess imageNames:(void(^)(NSString *imageStr))imageNamesBlcok faildBlock:(void(^)(NSError *error))faild;

/**返回字符串*/

- (void)postStrRequestWithURL:(NSString *)url parameters:(NSDictionary *)params successBlock:(void(^)(id  responseObject))success faildBlock:(void(^)(NSError *error))faild;

/**清空缓存*/
+ (void)clearCache;

/**获取缓存大小*/
+ (NSUInteger)getSize;

@end
